<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="1、携程2、美团3、爬虫4、自购5、其他" prop="chanelCode">
      <el-input v-model="dataForm.chanelCode" placeholder="1、携程2、美团3、爬虫4、自购5、其他"></el-input>
    </el-form-item>
    <el-form-item label="渠道房型编码" prop="chanelRoomCode">
      <el-input v-model="dataForm.chanelRoomCode" placeholder="渠道房型编码"></el-input>
    </el-form-item>
    <el-form-item label="房型编码" prop="roomCode">
      <el-input v-model="dataForm.roomCode" placeholder="房型编码"></el-input>
    </el-form-item>
    <el-form-item label="房型名称" prop="roomName">
      <el-input v-model="dataForm.roomName" placeholder="房型名称"></el-input>
    </el-form-item>
    <el-form-item label="最大入住人数" prop="maxNum">
      <el-input v-model="dataForm.maxNum" placeholder="最大入住人数"></el-input>
    </el-form-item>
    <el-form-item label="房间大小" prop="roomSize">
      <el-input v-model="dataForm.roomSize" placeholder="房间大小"></el-input>
    </el-form-item>
    <el-form-item label="房间所在楼层" prop="roomFloor">
      <el-input v-model="dataForm.roomFloor" placeholder="房间所在楼层"></el-input>
    </el-form-item>
    <el-form-item label="床型" prop="bedPad">
      <el-input v-model="dataForm.bedPad" placeholder="床型"></el-input>
    </el-form-item>
    <el-form-item label="床宽" prop="bedWidth">
      <el-input v-model="dataForm.bedWidth" placeholder="床宽"></el-input>
    </el-form-item>
    <el-form-item label="房间描述" prop="roomContent">
      <el-input v-model="dataForm.roomContent" placeholder="房间描述"></el-input>
    </el-form-item>
    <el-form-item label="房间窗户情况
            0:无窗/1:有窗/2:部分有窗/3:暗窗/4:部分暗窗" prop="windows">
      <el-input v-model="dataForm.windows" placeholder="房间窗户情况
            0:无窗/1:有窗/2:部分有窗/3:暗窗/4:部分暗窗"></el-input>
    </el-form-item>
    <el-form-item label="窗景描述" prop="windowInfo">
      <el-input v-model="dataForm.windowInfo" placeholder="窗景描述"></el-input>
    </el-form-item>
    <el-form-item label="宽带服务 A,B,C,D。分别代表： A：无宽带，B：免费宽带，C：收费宽带，D：部分收费宽带" prop="internet">
      <el-input v-model="dataForm.internet" placeholder="宽带服务 A,B,C,D。分别代表： A：无宽带，B：免费宽带，C：收费宽带，D：部分收费宽带"></el-input>
    </el-form-item>
    <el-form-item label="窗户不利因素" prop="windowBad">
      <el-input v-model="dataForm.windowBad" placeholder="窗户不利因素"></el-input>
    </el-form-item>
    <el-form-item label="加床情况" prop="upBed">
      <el-input v-model="dataForm.upBed" placeholder="加床情况"></el-input>
    </el-form-item>
    <el-form-item label="房型状态房型状态。0:正常，-1:删除，-2:停售" prop="roomStatus">
      <el-input v-model="dataForm.roomStatus" placeholder="房型状态房型状态。0:正常，-1:删除，-2:停售"></el-input>
    </el-form-item>
    <el-form-item label="房间最大容纳儿童人数" prop="maxChild">
      <el-input v-model="dataForm.maxChild" placeholder="房间最大容纳儿童人数"></el-input>
    </el-form-item>
    <el-form-item label="房型设施" prop="houseType">
      <el-input v-model="dataForm.houseType" placeholder="房型设施"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          chanelCode: '',
          chanelRoomCode: '',
          roomCode: '',
          roomName: '',
          maxNum: '',
          roomSize: '',
          roomFloor: '',
          bedPad: '',
          bedWidth: '',
          roomContent: '',
          windows: '',
          windowInfo: '',
          internet: '',
          windowBad: '',
          upBed: '',
          roomStatus: '',
          maxChild: '',
          houseType: ''
        },
        dataRule: {
          chanelCode: [
            { required: true, message: '1、携程2、美团3、爬虫4、自购5、其他不能为空', trigger: 'blur' }
          ],
          chanelRoomCode: [
            { required: true, message: '渠道房型编码不能为空', trigger: 'blur' }
          ],
          roomCode: [
            { required: true, message: '房型编码不能为空', trigger: 'blur' }
          ],
          roomName: [
            { required: true, message: '房型名称不能为空', trigger: 'blur' }
          ],
          maxNum: [
            { required: true, message: '最大入住人数不能为空', trigger: 'blur' }
          ],
          roomSize: [
            { required: true, message: '房间大小不能为空', trigger: 'blur' }
          ],
          roomFloor: [
            { required: true, message: '房间所在楼层不能为空', trigger: 'blur' }
          ],
          bedPad: [
            { required: true, message: '床型不能为空', trigger: 'blur' }
          ],
          bedWidth: [
            { required: true, message: '床宽不能为空', trigger: 'blur' }
          ],
          roomContent: [
            { required: true, message: '房间描述不能为空', trigger: 'blur' }
          ],
          windows: [
            { required: true, message: '房间窗户情况0:无窗/1:有窗/2:部分有窗/3:暗窗/4:部分暗窗不能为空', trigger: 'blur' }
          ],
          windowInfo: [
            { required: true, message: '窗景描述不能为空', trigger: 'blur' }
          ],
          internet: [
            { required: true, message: '宽带服务 A,B,C,D。分别代表： A：无宽带，B：免费宽带，C：收费宽带，D：部分收费宽带不能为空', trigger: 'blur' }
          ],
          windowBad: [
            { required: true, message: '窗户不利因素不能为空', trigger: 'blur' }
          ],
          upBed: [
            { required: true, message: '加床情况不能为空', trigger: 'blur' }
          ],
          roomStatus: [
            { required: true, message: '房型状态房型状态。0:正常，-1:删除，-2:停售不能为空', trigger: 'blur' }
          ],
          maxChild: [
            { required: true, message: '房间最大容纳儿童人数不能为空', trigger: 'blur' }
          ],
          houseType: [
            { required: true, message: '房型设施不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/ht/htchanelphysicalroom/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.chanelCode = data.htChanelPhysicalRoom.chanelCode
                this.dataForm.chanelRoomCode = data.htChanelPhysicalRoom.chanelRoomCode
                this.dataForm.roomCode = data.htChanelPhysicalRoom.roomCode
                this.dataForm.roomName = data.htChanelPhysicalRoom.roomName
                this.dataForm.maxNum = data.htChanelPhysicalRoom.maxNum
                this.dataForm.roomSize = data.htChanelPhysicalRoom.roomSize
                this.dataForm.roomFloor = data.htChanelPhysicalRoom.roomFloor
                this.dataForm.bedPad = data.htChanelPhysicalRoom.bedPad
                this.dataForm.bedWidth = data.htChanelPhysicalRoom.bedWidth
                this.dataForm.roomContent = data.htChanelPhysicalRoom.roomContent
                this.dataForm.windows = data.htChanelPhysicalRoom.windows
                this.dataForm.windowInfo = data.htChanelPhysicalRoom.windowInfo
                this.dataForm.internet = data.htChanelPhysicalRoom.internet
                this.dataForm.windowBad = data.htChanelPhysicalRoom.windowBad
                this.dataForm.upBed = data.htChanelPhysicalRoom.upBed
                this.dataForm.roomStatus = data.htChanelPhysicalRoom.roomStatus
                this.dataForm.maxChild = data.htChanelPhysicalRoom.maxChild
                this.dataForm.houseType = data.htChanelPhysicalRoom.houseType
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/ht/htchanelphysicalroom/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'chanelCode': this.dataForm.chanelCode,
                'chanelRoomCode': this.dataForm.chanelRoomCode,
                'roomCode': this.dataForm.roomCode,
                'roomName': this.dataForm.roomName,
                'maxNum': this.dataForm.maxNum,
                'roomSize': this.dataForm.roomSize,
                'roomFloor': this.dataForm.roomFloor,
                'bedPad': this.dataForm.bedPad,
                'bedWidth': this.dataForm.bedWidth,
                'roomContent': this.dataForm.roomContent,
                'windows': this.dataForm.windows,
                'windowInfo': this.dataForm.windowInfo,
                'internet': this.dataForm.internet,
                'windowBad': this.dataForm.windowBad,
                'upBed': this.dataForm.upBed,
                'roomStatus': this.dataForm.roomStatus,
                'maxChild': this.dataForm.maxChild,
                'houseType': this.dataForm.houseType
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
